package fast.loader;

import java.util.HashMap;

import fast.data.Stat;

public class ItemSuffixDB {
	
	private HashMap<Integer,String[]> random_suffix_data = ItemUpgrade.read("static/ItemRandomSuffix.dbc.csv",0);
	public HashMap<Integer,String[]> random_prop_points = ItemUpgrade.read("static/RandomPropPoints.dbc.csv",0);
	
	public Stat GetStat(int id, int index)
    {
		String[] data = random_suffix_data.get(id);
		return StatFromEnchantmentId(Integer.parseInt(data[3+index]));
    }
	
	public float GetStatValue(Item item, int id, int index)
    {
        int itemlevel = item.getItemLevel();
        int qualityindex = QualityIndex(item.getQuality());
        int slotindex = SlotIndex(item.getInventorySlot());
        String[] points = random_prop_points.get(itemlevel);
        int baseValue = Integer.parseInt(points[1+ qualityindex * 5 + slotindex]);
        String[] data = random_suffix_data.get(id);
        int multiplier = Integer.parseInt(data[8+index]);
        return (int)(multiplier / 10000.0 * baseValue);
    }
	
	public static int QualityIndex(int quality)
    {
        switch (quality)
        { 
            case 4:
            default:
                return 0;
            case 3:
                return 1;
            case 2:
                return 2;
        }
    }
	
	 public static int SlotIndex(int slot)
     {
         switch (slot)
         {
             case 1:
             case 5:
             case 7:
             //case ItemSlot.TwoHand:
                 return 0;
             case 3:
             case 10:
             case 6:
             case 8:
             case 12:
                 return 1;
             case 9:
             case 2:
             case 16:
             case 11:
             //case ItemSlot.OffHand:
             default:
                 return 2;
             //case ItemSlot.MainHand:
             case 13: // ItemSlot.OneHand:
                 return 3;
             case 15: // ItemSlot.Ranged:
                 return 4;
         }
     }
	 
	 private Stat StatFromEnchantmentId(int id)
     {
         switch (id)
         {
             case 2802:
                 return Stat.agi;
             case 2803:
                 return Stat.sta;
             case 2804:
                 return Stat.intt;
             case 2805:
                 return Stat.str;
             case 2806:
                 return Stat.spi;
             case 2813:
             case 2815:
                 return Stat.dodge;
             //case 2816:
             //    return "Mp5";
             case 2822:
             case 2823:
                 return Stat.cri;
             case 2824:
                 return Stat.sp;
             case 2825:
                 return Stat.ap;
             //case 2826:
             //    return "Block Rating";
             case 3726:
                 return Stat.hst;
             case 3727:
                 return Stat.hit;
             case 4058:
                 return Stat.exp;
             case 4059:
                 return Stat.mst;
             case 4060:
                 return Stat.parry;
         }
         return null;
     }
}

